#!/bin/bash
test=""
loop=""
at=""
ppp=""
diag=""
ping_time=""
for i in "$@"
do
	case $i in
		--test=*)
			test=${i#--test=}
			;;
		--loop=*)
			loop=${i#--loop=}
			;;
		--at=*)
			at=${i#--at=}
			;;
		--ppp=*)
			ppp=${i#--ppp=}
			;;		
		--diag=*)
			diag=${i#--diag=}
			;;
		--ping=*)
			ping_time=${i#--ping=}
			;;	
	esac
done   

if [ ! "$at" = "" ];then
	sed -i "s|dev_port = .*|dev_port = \"$at\"|" ../cfg/at/other.cfg
fi

if [ ! "$ppp" = "" ];then
	sed -i "s|DEVICE=/dev/.*|DEVICE=$ppp|" ../cfg/ppp/air-ppp-on
	sed -i "s|DEVICE=/dev/.*|DEVICE=$ppp|" ../cfg/ppp/air-ppp-off
	sed -i "s|DEVICE=/dev/.*|DEVICE=$ppp|" ../cfg/ppp/air-ppp-status
fi

if [ ! "$diag" = "" ];then
	sed -i "s|diag_log_port = .*|diag_log_port = \"$diag\"|" ../cfg/at/other.cfg
fi

case $test in
	ppp)
		sed -i "s|test_num = .*|test_num = 2|" ../cfg/at/other.cfg
		if [ ! "$loop" = "" ];then
			sed -i "s|test_ppp_loop = .*|test_ppp_loop = $loop|" ../cfg/at/other.cfg
		fi
		if [ ! "$ping_time" = "" ];then
			sed -i "s|ppp_ping_loop = .*|ppp_ping_loop = $ping_time|" ../cfg/at/other.cfg
		fi
		python2 main.py
		exit "$?"
		;;
	at)
		sed -i "s|test_num = .*|test_num = 1|" ../cfg/at/other.cfg
		if [ ! "$loop" = "" ]; then
			sed -i "s|test_basic_loop = .*|test_basic_loop = $loop|" ../cfg/at/other.cfg
		fi
		python2 main.py
		exit "$?"
		;;
	rndis)
		sed -i "s|test_num = .*|test_num = 3|" ../cfg/at/other.cfg
		if [ ! "$loop" = "" ];then
			sed -i "s|test_netCard_loop = .*|test_netCard_loop = $loop|" ../cfg/at/other.cfg
		fi
		if [ ! "$ping_time" = "" ];then
			sed -i "s|rndis_ping_loop = .*|rndis_ping_loop = $ping_time|" ../cfg/at/other.cfg
		fi
		python2 main.py
		exit "$?"
		;;
	cmux)
		sed -i "s|usb_port=.*|usb_port=$at|" cmux
		sed -i "s|test_num = .*|test_num = 4|" ../cfg/at/other.cfg
		if [ ! "$loop" = "" ];then
			sed -i "s|test_ppp_loop = .*|test_ppp_loop = $loop|" ../cfg/at/other.cfg
		fi
		if [ ! "$ping_time" = "" ];then
			sed -i "s|ppp_ping_loop = .*|ppp_ping_loop = $ping_time|" ../cfg/at/other.cfg
		fi
		./cmux
		exit "$?"
		;;
esac 
